package com.ccb.ha.zhxf.controller;

import com.ccb.ha.zhxf.entity.Province;
import com.ccb.ha.zhxf.result.Result;
import com.ccb.ha.zhxf.result.ResultEnum;
import com.ccb.ha.zhxf.result.ResultUtil;
import com.ccb.ha.zhxf.service.ProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/province")
public class ProvinceController {
    @Autowired
    private ProvinceService provinceService;

    @RequestMapping(value = "/FindAll", method = RequestMethod.POST)
    @ResponseBody
    public Result FindAll(){
        List<Province> provinces = provinceService.FindAll();
        if (provinces != null){

            return ResultUtil.success(provinces);
        }else {

            return ResultUtil.error(ResultEnum.DATA_IS_NULL.getCode(), ResultEnum.DATA_IS_NULL.getMsg());
        }
    }

    @RequestMapping(value = "/FindById", method = RequestMethod.POST)
    @ResponseBody
    public Result FindById(int mechanism_id){

        List<Province> provinces = provinceService.FindById(mechanism_id);
        if (provinces != null){
            return ResultUtil.success(provinces);
        }else {

            return ResultUtil.error(ResultEnum.DATA_IS_NULL.getCode(), ResultEnum.DATA_IS_NULL.getMsg());

        }
    }

    @RequestMapping(value = "/insertProvince", method = RequestMethod.POST)
    @ResponseBody
    public Result InsertProvince(@RequestParam("id") int id,
                                 @RequestParam("name") String name,
                                 @RequestParam("sex") String sex,
                                 @RequestParam("mechanism_id") String mechanism_id,
                                 @RequestParam("armyman") int armyman,
                                 @RequestParam("retire") int retire,
                                 @RequestParam("address") int address,
                                 @RequestParam("leader") int leader,
                                 @RequestParam("type_id") int type_id,
                                 @RequestParam("staydays") int staydays,
                                 @RequestParam("is_focus") int is_focus,
                                 @RequestParam("datatime") int datatime,
                                 @RequestParam("remarks") int remarks,
                                 @RequestParam("photo") int photo,
                                 @RequestParam("id_card") int id_card,
                                 @RequestParam("is_delet") int is_delet
                                 ){
        Province provinces = new Province();
        int result  = provinceService.InsertProvince(provinces, ddd);
        if (provinces != null){
            return ResultUtil.success(provinces);
        }else {

            return ResultUtil.error(ResultEnum.DATA_IS_NULL.getCode(), ResultEnum.DATA_IS_NULL.getMsg());

        }
    }
}
